﻿
using AutoMapper;
using OP30.AutoMapper;
using OP30.Views.ST00;
using OP30.Views.ST13;
using OP30.Views.ST16;

namespace OP30.Extensions
{
    public static class ContainerExtensions
    {
        public static void AddViews(this IContainerRegistry services)
        {

            //新增部分
            services.Add<MainWindow, MainWindowViewModel>(AppViews.MainWindow);
            services.Add<AllStationView, AllStationViewModel>(AppViews.AllStationView);
            services.Add<MenuView, MenuViewModel>(AppViews.MenuView);
            services.Add<AlarmsManagerView, AlarmsManagerViewModel>(AppViews.AlarmsManagerView);
            services.Add<AlarmsHistoryView, AlarmsHistoryViewModel>(AppViews.AlarmsHistoryView);

            services.Add<PingBiView, PingBiViewModel>(AppViews.PingBiView);
            services.Add<IOMonitorView, IOMonitorViewModel>(name: AppViews.IOMonitorView);
            services.Add<ProductStatisticView, ProductStatisticViewModel>(AppViews.ProductStatisticView);
            services.Add<LifeControlView, LifeControlViewModel>(AppViews.LifeControlView);
            services.Add<ContinuousNgView, ContinuousNgViewModel>(AppViews.ContinuousNgView);
            services.Add<CycleTimeStatisticView, CycleTimeStatisticViewModel>(AppViews.CycleTimeStatisticView);




            services.Add<ST00View, ST00ViewModel>(AppViews.ST00View);
            services.Add<ST01View, ST01ViewModel>(AppViews.ST01View);
            services.Add<ST03View, ST03ViewModel>(AppViews.ST03View);
            services.Add<ST05View, ST05ViewModel>(AppViews.ST05View);
            services.Add<ST09View, ST09ViewModel>(AppViews.ST09View);
            services.Add<ST11View, ST11ViewModel>(AppViews.ST11View);
            services.Add<ST13View, ST13ViewModel>(AppViews.ST13View);
            services.Add<ST16View, ST16ViewModel>(AppViews.ST16View);
            services.Add<ST00CyManagerView, ST00CyManagerViewModel>(AppViews.ST00CyManagerView);
            services.Add<ST00DeviceManagerView, ST00DeviceManagerViewModel>(AppViews.ST00DeviceManagerView);
            services.Add<ST01CyManagerView, ST01CyManagerViewModel>(AppViews.ST01CyManagerView);
            services.Add<ST01DeviceManagerView, ST01DeviceManagerViewModel>(AppViews.ST01DeviceManagerView);
            services.Add<ST03CyManagerView, ST03CyManagerViewModel>(AppViews.ST03CyManagerView);
            services.Add<ST03CCDManagerView,ST03CCDManagerViewModel>(AppViews.ST03CCDManagerView);
            services.Add<ST05CyManagerView, ST05CyManagerViewModel>(AppViews.ST05CyManagerView);
            services.Add<ST05ServoManagerView, ST05ServoManagerViewModel>(AppViews.ST05ServoManagerView);
            services.Add<ST05DeviceManagerView, ST05DeviceManagerViewModel>(AppViews.ST05DeviceManagerView);
            services.Add<ST09CyManagerView, ST09CyManagerViewModel>(AppViews.ST09CyManagerView);
            services.Add<ST11CyManagerView, ST11CyManagerViewModel>(AppViews.ST11CyManagerView);
            services.Add<ST11CCDManagerView, ST11CCDManagerViewModel>(AppViews.ST11CCDManagerView);
            services.Add<ST13CyManagerView, ST13CyManagerViewModel>(AppViews.ST13CyManagerView);
            services.Add<ST13ServoManagerView, ST13ServoManagerViewModel>(AppViews.ST13ServoManagerView);
            services.Add<ST16CyManagerView, ST16CyManagerViewModel>(AppViews.ST16CyManagerView);
            services.Add<LoginView, LoginViewModel>(AppViews.LoginView);
        }


        public static void AddAutoMapper(this IContainerRegistry services)
        {
            services.RegisterSingleton<IAutoMapperProvider, AutoMapperProvider>();
            services.Register(typeof(IMapper), GetMapper);
        }


        #region 私有方法

        private static void Add<TView, TViewModel>(this IContainerRegistry containerRegistry, string name = null)
        {
            containerRegistry.RegisterForNavigation<TView, TViewModel>(name);
        }

        private static IMapper GetMapper(IContainerProvider container)
        {
            var provider = container.Resolve<IAutoMapperProvider>();
            return provider.GetMapper();
        }

        #endregion
    }
}
